package com.zhuoyue.system.service.impl;

import com.zhuoyue.common.annotation.DataScope;
import com.zhuoyue.common.core.domain.ChartData;
import com.zhuoyue.system.domain.po.SelectTimePo;
import com.zhuoyue.system.domain.po.TblAppUserPo;
import com.zhuoyue.system.domain.vo.AppUserPositionVo;
import com.zhuoyue.system.domain.vo.TblAppUserVo;
import com.zhuoyue.system.mapper.TblAppUserMapper;
import com.zhuoyue.system.service.ITblAppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * APP用户Service业务层处理
 *
 * @author hewenze
 * @date 2020-08-05
 */
@Service
public class TblAppUserServiceImpl implements ITblAppUserService {
    @Autowired
    private TblAppUserMapper tblAppUserMapper;


    /**
     * 查询APP用户列表
     *
     * @param tblAppUserPo APP用户
     * @return APP用户
     */
    @Override
    @DataScope(deptAlias = "s_d")
    public List<TblAppUserVo> selectTblAppUserList(TblAppUserPo tblAppUserPo) {
        return tblAppUserMapper.selectTblAppUserList(tblAppUserPo);
    }

    /**
     * 查询APP用户列表
     *
     * @param tblAppUserPo APP用户
     * @return APP用户
     */
    @Override
    @DataScope(deptAlias = "s_d")
    public List<TblAppUserVo> selectTblAppUserPushList(TblAppUserPo tblAppUserPo) {
        return tblAppUserMapper.selectTblAppUserPushList(tblAppUserPo);
    }

    @Override
    public TblAppUserVo selectTblAppUserByAccountAndOrgCode(String account, String orgCode) {
        return tblAppUserMapper.selectTblAppUserOne(account, orgCode);
    }

    @Override
    @DataScope(deptAlias = "s_d")
    public List<AppUserPositionVo> selectAppUserPositionList(TblAppUserPo tblAppUserPo) {
        List<AppUserPositionVo> appUserPositionVos = tblAppUserMapper.selectAppUserPositionList(tblAppUserPo);
        //获取位置最后一次上报的时间
//        appUserPositionVos.forEach(item -> {
//            LocalDateTime latestTime = item.getModifyTime() == null ? item.getCreateTime() : item.getModifyTime();
//            item.setLatestTime(latestTime);
//        });
        return appUserPositionVos;
    }

    @Override
    @DataScope(deptAlias = "s_d")
    public List<Integer> selectTblAppUserCount(TblAppUserPo tblAppUserPo) {
        return tblAppUserMapper.selectTblAppUserCount(tblAppUserPo);
    }

    @Override
    @DataScope(deptAlias = "s_d")
    public int getRegisterCount(SelectTimePo selectTimePo) {
        return tblAppUserMapper.getRegisterCount(selectTimePo);
    }

    @Override
    @DataScope(deptAlias = "s_d")
    public List<ChartData> getRegisterCountOfDays(SelectTimePo selectTimePo) {
        return tblAppUserMapper.getRegisterCountOfDays(selectTimePo);
    }
}
